package server

import (
	"server5/Bean"
	"server5/Interface"
	"server5/utils"
)

type User struct {
	connection Interface.IConnection
	userInfo Bean.UserInfo
	gameRoom Interface.IGameRoom
	status int32
}

func NewUser(conn Interface.IConnection,userInfo Bean.UserInfo) *User {
	return &User{
		connection: conn,
		userInfo:   userInfo,
		gameRoom:   nil,
		status:     utils.NotLogin,
	}
}

//增加经验，经验到达最大值不增长。返回升至下一级所需经验 和 升了多少级（增加了多少个技能点）
func (u *User) AddExp(exp int) (nextExp int, AddSp int) {
	u.userInfo.UserExp += exp

	for u.userInfo.UserExp >= utils.ExpList[u.userInfo.UserLv] {
		if u.userInfo.UserLv >= utils.MaxUserLv {
			//等级和经验到达最大值
			u.userInfo.UserExp = utils.ExpList[u.userInfo.UserLv]
		} else {
			u.userInfo.UserLv++
			u.userInfo.UserSp++
			AddSp++
		}
	}
	nextExp = utils.ExpList[u.userInfo.UserLv]
	return
}

func (u *User) AddGold(gold int) {
	u.userInfo.UserGold += gold
}

func (u *User) Status() int32 {
	return u.status
}

func (u *User) SetStatus(status int32) {
	u.status = status
}

func (u *User) GameRoom() Interface.IGameRoom {
	return u.gameRoom
}

func (u *User) SetGameRoom(gameRoom Interface.IGameRoom) {
	u.gameRoom = gameRoom
}

func (u *User) UserInfo() Bean.UserInfo {
	return u.userInfo
}

func (u *User) SetUserInfo(userInfo Bean.UserInfo) {
	u.userInfo = userInfo
}

func (u *User) Connection() Interface.IConnection {
	return u.connection
}

func (u *User) SetConnection(connection Interface.IConnection) {
	u.connection = connection
}